home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10041 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  39 lines

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP! Modifying the EOF in a file!
  5. Date: 14 Mar 1996 17:00:10 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4iafeqINNbqp@anvil.ugrad.cs.ubc.ca>
  8. References: <4i585k$4ia@news.netam.net>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10.  
  11. In article <4i585k$4ia@news.netam.net>,
  12. The Bowling Green Connection <bgc@alpha.netam.net> wrote:
  13.  >I am having trouble shortening the size of a text file...
  14.  >Suppose I have a text file with 3 lines of data, then I
  15.  >run this program:
  16.  >
  17.  >void main() {
  18.  >   FILE *dat;
  19.  >   dat=fopen("file.txt", "r+");
  20.  >   fprintf(dat, "Hello! %c", EOF);
  21.  >   fclose(dat);
  22.  >}
  23.  >
  24.  >Why doesn't the EOF character chop off the remaining two lines?
  25.  >When I print out the file after running this program, the ONLY thing
  26.  >that changed was the first few characters.. The other two lines
  27.  >still remain..  HELP!
  28.  
  29. I think what everybody is trying to tell you, and failing miserably, is that
  30. EOF is not actually part of the contents of a stream. It is a ``sentinel''---a
  31. value returned from the file manipulation routines to indicate that there
  32. are no more characters. It is not part of the file, it's just a special return
  33. value guaranteed to be different from every character.
  34.  
  35. Without this special marker it would be awkward for these routines to signal
  36. the end of file condition. 
  37. -- 
  38.  
  39.